﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace CarlowPitBoy
{
    class Terrain
    {
        private  int _existsSwapValue = 0;

        public  string name = "no name";
        public  string animation = "( none )";
        public  bool collidable = false;


        public  bool dialogueInteractBool = false;
        public  bool dialogueAreaEnterBool = false;
        public  bool dialogueItemReceiveBool = false;

        public  string dialogueInteractText = "";
        public  string dialogueAreaEnterText = "";
        public  string dialogueItemReceiveText = "";

        public  string dialogueItemReceiveItem = "";


        public  bool giveItemBool = false;
        public  string giveItemItem = "";


        public  string itemSquareItemCreated = "";

        public  bool itemSquareInteractBool = false;
        public  bool itemSquareItemReceiveBool = false;

        public  string itemSquareInteractText = "";
        public  string itemSquareItemReceiveText = "";

        public  string itemSquareItemReceiveItem = "";


        public  string characterSquareCharacterCreated = "";

        public  bool characterSquareInteractBool = false;
        public  bool characterSquareItemReceiveBool = false;

        public  string characterSquareInteractText = "";
        public  string characterSquareItemReceiveText = "";

        public  string characterSquareItemReceiveItem = "";



        public  bool existsBool = true;
        public  string existsMagicSwapper = "Fire";
        public  string existsGtLtEq = "=";
        public  int existsSwapValue
        {
            get { return _existsSwapValue; }
            set
            {
                int retVal = 0;
                try
                {
                    retVal = Convert.ToInt32(value);
                }
                catch (Exception)
                {
                    MessageBox.Show("This text box only takes numbers.", "Only Numbers Can be in this box", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    retVal = 0;
                }
                if (retVal > GameProperties.MAX_MAGIC_VALUE)
                {
                    MessageBox.Show("Magic value cannot exceed " + GameProperties.MAX_MAGIC_VALUE.ToString() + ".", "Exceeded max Magic value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    retVal = 0;
                }
                else if (retVal < GameProperties.MIN_MAGIC_VALUE)
                {
                    MessageBox.Show("Magic value cannot be less than " + GameProperties.MIN_MAGIC_VALUE.ToString() + ".", "Below minimum Magic value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    retVal = 0;
                }
                _existsSwapValue = retVal;
            }
        }

        public  bool questRelated = false;
        public  bool loadPoint = false;

        public  bool teleportsBool = false;
        public  string teleportsMap = "";
        public  string teleportsLoadPoint = "";

        public  bool rememberMagicState = false;

        public  string memorisedCondition1 = "( none )";
        public  string memorisedCon1Choice1 = "";
        public  string memorisedCon1Choice2 = "";
        public  string memorisedCon1Choice3 = "";
        public  string memorisedCon1Choice4 = "";

        public  string memorisedCondition2 = "( none )";
        public  string memorisedCon2Choice1 = "";
        public  string memorisedCon2Choice2 = "";
        public  string memorisedCon2Choice3 = "";
        public  string memorisedCon2Choice4 = "";

        public  string memorisedCondition3 = "( none )";
        public  string memorisedCon3Choice1 = "";
        public  string memorisedCon3Choice2 = "";
        public  string memorisedCon3Choice3 = "";
        public  string memorisedCon3Choice4 = "";

        public  string memorisedCondition4 = "( none )";
        public  string memorisedCon4Choice1 = "";
        public  string memorisedCon4Choice2 = "";
        public  string memorisedCon4Choice3 = "";
        public  string memorisedCon4Choice4 = "";

        public  string memorisedCondition5 = "( none )";
        public  string memorisedCon5Choice1 = "";
        public  string memorisedCon5Choice2 = "";
        public  string memorisedCon5Choice3 = "";
        public  string memorisedCon5Choice4 = "";

        public  string activatesMemory1Map = "";
        public  string activatesMemory1Object = "";
        /// <summary>
        /// e.g Memory 2 OR Special Animation 1
        /// </summary>
        public  string activatesMemory1Memory = "";


        public  string activatesMemory2Map = "";
        public  string activatesMemory2Object = "";
        /// <summary>
        /// e.g Memory 3 OR Special Animation 1
        /// </summary>
        public  string activatesMemory2Memory = "";

        public  string activatesMemory3Map = "";
        public  string activatesMemory3Object = "";
        /// <summary>
        /// e.g Memory 2 OR Special Animation 1
        /// </summary>
        public  string activatesMemory3Memory = ""; 

        public  void save()
        {
            try
            {
                XmlTextWriter terrainWriter = new XmlTextWriter(@"Map Objects\Terrain\" + name + ".ter.xml", null);
                terrainWriter.Formatting = Formatting.Indented;
                terrainWriter.WriteStartDocument();
                terrainWriter.WriteComment(name + " created on " + DateTime.UtcNow.ToString());

                terrainWriter.WriteStartElement("FileInformation");

                terrainWriter.WriteStartElement("Name");
                terrainWriter.WriteString(name);
                terrainWriter.WriteEndElement();//Name


                terrainWriter.WriteStartElement("AnimationFile");
                terrainWriter.WriteString(animation);
                terrainWriter.WriteEndElement();//Animation File


                terrainWriter.WriteStartElement("Collidable");
                terrainWriter.WriteString(collidable.ToString());
                terrainWriter.WriteEndElement();//Collidable

                terrainWriter.WriteStartElement("QuestRelated");
                terrainWriter.WriteString(questRelated.ToString());
                terrainWriter.WriteEndElement();//Quest Related


                terrainWriter.WriteStartElement("ShowDialogueInformation");

                terrainWriter.WriteStartElement("Interact");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(dialogueInteractBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(dialogueInteractText);
                terrainWriter.WriteEndElement();//Text

                terrainWriter.WriteEndElement();//Interact

                terrainWriter.WriteStartElement("AreaEnter");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(dialogueAreaEnterBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(dialogueAreaEnterText);
                terrainWriter.WriteEndElement();//Text

                terrainWriter.WriteEndElement();//Area Enter

                terrainWriter.WriteStartElement("ItemReceive");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(dialogueItemReceiveBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(dialogueItemReceiveItem);
                terrainWriter.WriteEndElement();//Text

                terrainWriter.WriteEndElement();//Item Receive

                terrainWriter.WriteEndElement();//ShowDialogueInformation

                terrainWriter.WriteStartElement("GivesItemInformation");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(giveItemBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(dialogueItemReceiveItem);
                terrainWriter.WriteEndElement();//Text

                terrainWriter.WriteStartElement("ItemFile");
                terrainWriter.WriteString(giveItemItem);
                terrainWriter.WriteEndElement();//Item File

                terrainWriter.WriteEndElement();//GivesItemInformation


                terrainWriter.WriteStartElement("ItemAtSquareInformation");

                terrainWriter.WriteStartElement("ItemCreated");
                terrainWriter.WriteStartElement(itemSquareItemCreated);
                terrainWriter.WriteEndElement();//Item Created

                terrainWriter.WriteStartElement("Interact");
                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(itemSquareInteractBool.ToString());
                terrainWriter.WriteEndElement();//Bool
                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(itemSquareInteractText);
                terrainWriter.WriteEndElement();//Text
                terrainWriter.WriteEndElement();//Interact

                terrainWriter.WriteStartElement("ItemReceive");
                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(itemSquareItemReceiveBool.ToString());
                terrainWriter.WriteEndElement();//Bool
                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(itemSquareItemReceiveText);
                terrainWriter.WriteEndElement();//Text
                terrainWriter.WriteStartElement("Item");
                terrainWriter.WriteStartElement(itemSquareItemReceiveItem);
                terrainWriter.WriteEndElement();//Item
                terrainWriter.WriteEndElement();//Item Receive

                terrainWriter.WriteEndElement();//ItemAtSquareInformation


                terrainWriter.WriteStartElement("CharacterAtSquareInformation");

                terrainWriter.WriteStartElement("CharacterCreated");
                terrainWriter.WriteStartElement(characterSquareCharacterCreated);
                terrainWriter.WriteEndElement();//Character Created

                terrainWriter.WriteStartElement("Interact");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(characterSquareInteractBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(characterSquareInteractText);
                terrainWriter.WriteEndElement();//Text

                terrainWriter.WriteEndElement();//Interact

                terrainWriter.WriteStartElement("ItemReceive");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(characterSquareItemReceiveBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Text");
                terrainWriter.WriteString(characterSquareItemReceiveText);
                terrainWriter.WriteEndElement();//Text

                terrainWriter.WriteStartElement("Item");
                terrainWriter.WriteStartElement(characterSquareItemReceiveItem);
                terrainWriter.WriteEndElement();//Item

                terrainWriter.WriteEndElement();//Item Receive

                terrainWriter.WriteEndElement();//CharacterAtSquareInformation


                terrainWriter.WriteStartElement("ExistsOnMapInformation");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(existsBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("MagicSwapper");
                terrainWriter.WriteString(existsMagicSwapper);
                terrainWriter.WriteEndElement();//Magic Swapper

                terrainWriter.WriteStartElement("EqualGreaterLess");
                terrainWriter.WriteString(existsGtLtEq.ToString());
                terrainWriter.WriteEndElement();//Equal Greater Less

                terrainWriter.WriteStartElement("SwapValue");
                terrainWriter.WriteString(_existsSwapValue.ToString());
                terrainWriter.WriteEndElement();//Swap Value

                terrainWriter.WriteEndElement();//ExistsOnMapInformation


                terrainWriter.WriteStartElement("LoadPoint");
                terrainWriter.WriteString(loadPoint.ToString());
                terrainWriter.WriteEndElement();//Load Point


                terrainWriter.WriteStartElement("TeleportsInformation");

                terrainWriter.WriteStartElement("Bool");
                terrainWriter.WriteString(teleportsBool.ToString());
                terrainWriter.WriteEndElement();//Bool

                terrainWriter.WriteStartElement("Map");
                terrainWriter.WriteString(teleportsMap);
                terrainWriter.WriteEndElement();

                terrainWriter.WriteStartElement("LoadPoint");//N.B Consider Changing Name
                terrainWriter.WriteString(teleportsLoadPoint);
                terrainWriter.WriteEndElement();

                terrainWriter.WriteEndElement();//TeleportsInformation


                terrainWriter.WriteStartElement("RememberMagicState");
                terrainWriter.WriteString(rememberMagicState.ToString());
                terrainWriter.WriteEndElement();//Remembers Magic State



                terrainWriter.WriteStartElement("MemorisedConditions");


                terrainWriter.WriteStartElement("Condition1");

                terrainWriter.WriteStartElement("ConditionName");
                terrainWriter.WriteString(memorisedCondition1);
                terrainWriter.WriteEndElement();//Condition Name

                terrainWriter.WriteStartElement("Choice1");
                terrainWriter.WriteString(memorisedCon1Choice1);
                terrainWriter.WriteEndElement();//Choice 1

                terrainWriter.WriteStartElement("Choice2");
                terrainWriter.WriteString(memorisedCon1Choice2);
                terrainWriter.WriteEndElement();//Choice 2

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon1Choice3);
                terrainWriter.WriteEndElement();//Choice 3

                terrainWriter.WriteStartElement("Choice4");
                terrainWriter.WriteString(memorisedCon1Choice4);
                terrainWriter.WriteEndElement();//Choice 4

                terrainWriter.WriteEndElement();//Condition 1


                terrainWriter.WriteStartElement("Condition2");

                terrainWriter.WriteStartElement("ConditionName");
                terrainWriter.WriteString(memorisedCondition2);
                terrainWriter.WriteEndElement();//Condition Name

                terrainWriter.WriteStartElement("Choice1");
                terrainWriter.WriteString(memorisedCon2Choice1);
                terrainWriter.WriteEndElement();//Choice 1

                terrainWriter.WriteStartElement("Choice2");
                terrainWriter.WriteString(memorisedCon2Choice2);
                terrainWriter.WriteEndElement();//Choice 2

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon2Choice3);
                terrainWriter.WriteEndElement();//Choice 3

                terrainWriter.WriteStartElement("Choice4");
                terrainWriter.WriteString(memorisedCon2Choice4);
                terrainWriter.WriteEndElement();//Choice 4

                terrainWriter.WriteEndElement();//Condition 2


                terrainWriter.WriteStartElement("Condition3");

                terrainWriter.WriteStartElement("ConditionName");
                terrainWriter.WriteString(memorisedCondition3);
                terrainWriter.WriteEndElement();//Condition Name

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon3Choice1);
                terrainWriter.WriteEndElement();//Choice 1

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon3Choice2);
                terrainWriter.WriteEndElement();//Choice 2

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon3Choice3);
                terrainWriter.WriteEndElement();//Choice 3

                terrainWriter.WriteStartElement("Choice4");
                terrainWriter.WriteString(memorisedCon3Choice4);
                terrainWriter.WriteEndElement();//Choice 4

                terrainWriter.WriteEndElement();//Condition 3


                terrainWriter.WriteStartElement("Condition4");

                terrainWriter.WriteStartElement("ConditionName");
                terrainWriter.WriteString(memorisedCondition4);
                terrainWriter.WriteEndElement();//Condition Name

                terrainWriter.WriteStartElement("Choice1");
                terrainWriter.WriteString(memorisedCon4Choice1);
                terrainWriter.WriteEndElement();//Choice 1

                terrainWriter.WriteStartElement("Choice2");
                terrainWriter.WriteString(memorisedCon4Choice2);
                terrainWriter.WriteEndElement();//Choice 2

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon4Choice3);
                terrainWriter.WriteEndElement();//Choice 3

                terrainWriter.WriteStartElement("Choice4");
                terrainWriter.WriteString(memorisedCon4Choice4);
                terrainWriter.WriteEndElement();//Choice 4

                terrainWriter.WriteEndElement();//Condition 4


                terrainWriter.WriteStartElement("Condition5");

                terrainWriter.WriteStartElement("ConditionName");
                terrainWriter.WriteString(memorisedCondition5);
                terrainWriter.WriteEndElement();//Condition Name

                terrainWriter.WriteStartElement("Choice1");
                terrainWriter.WriteString(memorisedCon5Choice1);
                terrainWriter.WriteEndElement();//Choice 1

                terrainWriter.WriteStartElement("Choice2");
                terrainWriter.WriteString(memorisedCon5Choice2);
                terrainWriter.WriteEndElement();//Choice 2

                terrainWriter.WriteStartElement("Choice3");
                terrainWriter.WriteString(memorisedCon5Choice3);
                terrainWriter.WriteEndElement();//Choice 3

                terrainWriter.WriteStartElement("Choice4");
                terrainWriter.WriteString(memorisedCon5Choice4);
                terrainWriter.WriteEndElement();//Choice 4

                terrainWriter.WriteEndElement();//Condition 5


                terrainWriter.WriteEndElement();//Memorised Conditions



                terrainWriter.WriteStartElement("ActivatesMemorisedConditions");


                terrainWriter.WriteStartElement("Condition1");

                terrainWriter.WriteStartElement("Map");
                terrainWriter.WriteString(activatesMemory1Map);
                terrainWriter.WriteEndElement();//Map

                terrainWriter.WriteStartElement("Object");
                terrainWriter.WriteString(activatesMemory1Object);
                terrainWriter.WriteEndElement();//Object

                terrainWriter.WriteStartElement("Memory");
                terrainWriter.WriteString(activatesMemory1Memory);
                terrainWriter.WriteEndElement();//Memory

                terrainWriter.WriteEndElement();//Condition 1


                terrainWriter.WriteStartElement("Condition2");

                terrainWriter.WriteStartElement("Map");
                terrainWriter.WriteString(activatesMemory2Map);
                terrainWriter.WriteEndElement();//Map

                terrainWriter.WriteStartElement("Object");
                terrainWriter.WriteString(activatesMemory2Object);
                terrainWriter.WriteEndElement();//Object

                terrainWriter.WriteStartElement("Memory");
                terrainWriter.WriteString(activatesMemory2Memory);
                terrainWriter.WriteEndElement();//Memory

                terrainWriter.WriteEndElement();//Condition 2


                terrainWriter.WriteStartElement("Condition3");

                terrainWriter.WriteStartElement("Map");
                terrainWriter.WriteString(activatesMemory3Map);
                terrainWriter.WriteEndElement();//Map

                terrainWriter.WriteStartElement("Object");
                terrainWriter.WriteString(activatesMemory3Object);
                terrainWriter.WriteEndElement();//Object

                terrainWriter.WriteStartElement("Memory");
                terrainWriter.WriteString(activatesMemory3Memory);
                terrainWriter.WriteEndElement();//Memory

                terrainWriter.WriteEndElement();//Condition 3


                terrainWriter.WriteEndElement();//ActivatesMemorisedConditions

                terrainWriter.WriteEndElement();//FileInformation

                terrainWriter.WriteEndDocument();
                terrainWriter.Flush();
                terrainWriter.Close();
            }
            catch(Exception xmlException)
            {
                MessageBox.Show(xmlException.ToString());
            }
        }
    }
}
